#include<stdio.h>
#include<stdlib.h>
struct Point{
	int x;
	int y;
}point={0,0};
template<class Data>
class Queue{
private:
	Data data;
	class Queue* ptop;
	class Queue* pdown;
	int now;
public:
	Queue()
	{
		ptop=(class Queue*)malloc(sizeof(class Queue));
		if(ptop==NULL)
			exit(0);
		ptop->pdown=NULL;
		ptop->ptop=NULL;
		pdown=ptop;
		now=0;
	}
	~Queue()
	{
		while(1)
		{
			if(ptop==pdown)
				break;
			class Queue* ptemp=ptop->pdown;
			free(ptop);
			ptop=ptemp;
		}
	}
	int cleanQueue()
	{
		while(1)
		{
			if(ptop==pdown)
				break;
			class Queue* ptemp=ptop->pdown;
			free(ptop);
			ptop=ptemp;
		}
		now=0;
		return 0;
	}
	int putinto(Data num)
	{
		class Queue* ptemp=pdown;
		pdown->data=num;
		pdown=(class Queue*)malloc(sizeof(class Queue));
		if(pdown==NULL)
			exit(0);
		ptemp->pdown=pdown;
		pdown->pdown=NULL;
		pdown->ptop=ptemp;
		now++;
	}
	Data gettop()
	{
		return ptop->data;
	}
	Data putout()
	{
		Data temp=ptop->data;
		if(ptop==pdown)
			return temp; 
		class Queue* ptemp=ptop->pdown;
		free(ptop);
		ptop=ptemp;
		if(now>0)
			now--;
		return temp;
	}
	inline int show_now()
	{
		return now;
	}
	bool findData(Data temp)
	{
		class Queue* ptemp=ptop;
		while(1)
		{
			if(ptemp==pdown||ptemp==NULL)
				break;
			if(ptemp->data==temp)
				return true;
			ptemp=ptemp->pdown;
		}
		return false;
	}
	bool is_empty()
	{
		if(now)
			return true;
		else 
			return false;
	}
};
bool BFS(int (*p)[8],int nogo,int no,int end,Point point,int* pflag)
{
	Queue<Point> queue;
	queue.putinto(point);
	Point pre=point;
	p[point.x][point.y]=*pflag+1;
	while(1)
	{
		if(queue.is_empty()==false)
			return false;
		point=queue.putout();
		pre=point;
		*pflag=p[point.x][point.y]+1;
		if(p[point.x][point.y]==end)
			return true;
		if(point.x+1<8&&p[point.x+1][point.y]!=no&&\
		(p[point.x+1][point.y]==nogo||p[point.x+1][point.y]==end))
		{
			point.x++;
			if(p[point.x][point.y]==end)
				return true;
			else
				p[point.x][point.y]=*pflag;
			queue.putinto(point);
		}
		point=pre;
		if(point.x-1>=0&&p[point.x-1][point.y]!=no&&\
		(p[point.x-1][point.y]==nogo||p[point.x-1][point.y]==end))
		{
			point.x--;
			if(p[point.x][point.y]==end)
				return true;
			else
				p[point.x][point.y]=*pflag;
			queue.putinto(point);
		}
		point=pre;
		if(point.y-1>=0&&p[point.x][point.y-1]!=no&&\
		(p[point.x][point.y-1]==nogo||p[point.x][point.y-1]==end))
		{
			point.y--;
			if(p[point.x][point.y]==end)
				return true;
			else
				p[point.x][point.y]=*pflag;
			queue.putinto(point);
		}
		point=pre;
		if(point.y+1<8&&p[point.x][point.y+1]!=no&&\
		(p[point.x][point.y+1]==nogo||p[point.x][point.y+1]==end))
		{
			point.y++;
			if(p[point.x][point.y]==end)
				return true;
			else
				p[point.x][point.y]=*pflag;
			queue.putinto(point);
		}
	}
}
void printAll(int (*p)[8])
{
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8;j++)
		{
			printf("%5d",p[i][j]);
			if(j==7)
				printf("\n");
		}
	}
}
int main()
{
	int p[8][8]=
	{
		{1,1,1,0,0,1,1,1,},
		{1,0,1,1,1,0,0,1,},
		{1,1,1,0,1,1,1,1,},
		{0,0,1,0,1,0,1,0,},
		{1,1,1,0,1,0,1,0,},
		{0,1,0,0,1,0,1,0,},
		{0,1,0,1,1,1,1,0,},
		{1,1,0,1,0,0,1,-1,},
	},num=1;
	if(BFS(p,1,0,-1,point,&num))
		printf("yes\n");
	printAll(p);
	printf("%d",num);
	return 0;
} 
